#include"Taskqueue.hh"
#include<memory>

using std::unique_lock;

TaskQueue::TaskQueue(int size)
    :_mut()
     ,_quesize(size)
     ,_notempty()
     ,_notfull()
     ,_queue()
     ,_loop(true)
{}

TaskQueue::~TaskQueue()
{

}

    bool TaskQueue::isempty()
{
    return 0==_queue.size();


}

    bool TaskQueue::isfull()
{
    return _quesize==(int)_queue.size();
}

    void TaskQueue::push(ele& rhs)
{
    unique_lock<mutex> _lock(_mut);
    while(isfull()&&_loop)
    {
        _notfull.wait(_lock);
    }
    _queue.push(rhs);
    _notempty.notify_one();
}

    ele TaskQueue::pop()
{
    unique_lock<mutex> _lock(_mut);
    while(isempty()&&_loop)
    {
        _notempty.wait(_lock);
    }
    ele tmp= _queue.back();
    _queue.pop();
    _notfull.notify_one();
    return tmp;
}
    void TaskQueue::wakeup()
{
    _loop=false;
    _notempty.notify_all();
}
